﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using AbcCorp.BLO;
using AbcCorp.DTO;

namespace AbcCorp.OrderService
{
    public class OrderService : IOrderService
    {
        public Order GetOrder(int orderid)
        {
            var orderBlo = new OrderBlo();
            var orderDto = orderBlo.GetOrder(orderid);
            var order = new Order();
            CopyObject<OrderDto, Order>.CopyProperties(orderDto, order);
            return order;
        }
        public IList<Order> GetOrders()
        {
            IList<Order> lstorder = new List<Order>();
            var orderBlo = new OrderBlo();
            var orders = orderBlo.GetOrders();
            if (orders == null) return null;
            foreach (var orderDto in orders)
            {
                var order = new Order();
                CopyObject<OrderDto, Order>.CopyProperties(orderDto, order);
                lstorder.Add(order);
            }            
            return lstorder;
        }

        public bool AddOrder(Order newOrder)
        {
            var orderBlo = new OrderBlo();
            var orderDto = new OrderDto();
            CopyObject<Order, OrderDto>.CopyProperties(newOrder, orderDto);
            return orderBlo.AddOrder(orderDto);
        }

         public bool UpdateOrder(int id, bool status)
         {
             var orderBlo = new OrderBlo();
            return orderBlo.UpdateOrder(id, status);
        }

        public IList<PaymentMethod> GetMethods()
        {
            IList<PaymentMethod> lstMethod = new List<PaymentMethod>();
            var methodBlo = new PaymentMethodBol();

            foreach (var methodDto in methodBlo.GetMethods())
            {
                var method = new PaymentMethod();
                CopyObject<PaymentMethodDto, PaymentMethod>.CopyProperties(methodDto, method);
                lstMethod.Add(method);
            }

            return lstMethod;
        }

        public IList<Order> GetOrderDetailsOfCustomer(int customerid)
        {
            IList<Order> lstOrder = new List<Order>();
            var orderBlo = new OrderBlo();
            var lstOrderDto = orderBlo.GetOrderDetailsOfCustomer(customerid);

            if(lstOrderDto == null) return null;

            foreach (var orderDto in lstOrderDto)
            {
                var order = new Order();
                CopyObject<OrderDto, Order>.CopyProperties(orderDto, order);
                lstOrder.Add(order);
            }
            return lstOrder;
        }
    }
}
